package com.spontaneappnew;

import java.util.ArrayList;
import java.util.Date;

import org.json.JSONArray;
import org.json.JSONException;

import com.parse.ParseFile;
import com.parse.ParseGeoPoint;
import com.parse.ParseObject;

public class Place {
	
	private String name, description, country, city, street;
	private Date date;
	private float rating;
	private int numOfImages;
	private String id;
	private ParseGeoPoint location;
	private String categoryId, userID;
	private ArrayList<String> commentsArray;
	private ArrayList<ParseFile> imagesArray;
	private ArrayList<ParseFile> thumbnailsArray;
	
	// Constructor that gets a date - used when constructing a place from the server on load screen
	public Place(String id, String name, String description, Date date, 
			String country, String city, String street, float rating,
			double latitude, double longitude, String categoryId, String userId, JSONArray comments, int numOfImages, ParseFile img1,ParseFile img2,ParseFile img3,
			ParseFile img4,ParseFile img5,ParseFile img6,ParseFile tmb1,ParseFile tmb2,ParseFile tmb3,ParseFile tmb4 ,ParseFile tmb5, ParseFile tmb6 ) {
		this.id = id;
		this.name = name;
		this.description = description;
		this.date = date;
		this.country = country;
		this.city = city;
		this.street = street;
		this.rating = rating;
		this.location = new ParseGeoPoint(latitude, longitude);
		this.categoryId = categoryId;
 		this.userID = userId;
 		this.commentsArray = new ArrayList<String>();
 		if (comments!=null){
 			int numOfIds=comments.length();
 			for (int i=0; i<numOfIds;i++){
 				try {
 					commentsArray.add(comments.getString(i));
 				} catch (JSONException e) {
 					e.printStackTrace();
 				}
 			}
 		}
 		this.imagesArray = new ArrayList<ParseFile>();
 		this.thumbnailsArray = new ArrayList<ParseFile>();
 		if (img1!=null){
 			imagesArray.add(img1);
 			thumbnailsArray.add(tmb1);
 		}
 		if (img2!=null){
 			imagesArray.add(img2);
 			thumbnailsArray.add(tmb2);
 		}
 		if (img3!=null){
 			imagesArray.add(img3);
 			thumbnailsArray.add(tmb3);
 		}
 		if (img4!=null){
 			imagesArray.add(img4);
 			thumbnailsArray.add(tmb4);
 		}
 		if (img5!=null){
 			imagesArray.add(img5);
 			thumbnailsArray.add(tmb5);
 		}
 		if (img6!=null){
 			imagesArray.add(img6);
 			thumbnailsArray.add(tmb6);
 		}
 		this.numOfImages = numOfImages;
	}
	
	// Constructor that is used when user adds a new place of his own
	public Place(String name, String description,
			String country, String city, String street, float rating,
			double latitude, double longitude, String categoryId, Date date, String FBuserId) {
		this.name = name;
		this.description = description;
		this.country = country;
		this.city = city;
		this.date = date;
		this.street = street;
		this.rating = rating;
		this.commentsArray = new ArrayList<String>();
		this.location = new ParseGeoPoint(latitude, longitude);
		this.categoryId = categoryId;
 		this.userID = FBuserId;
 		this.imagesArray = new ArrayList<ParseFile>();
 		this.thumbnailsArray = new ArrayList<ParseFile>();
 		this.commentsArray = new ArrayList<String>();
 		this.numOfImages=0;
	}
	
	// Empty constructor
	public Place() {
		this.name = null;
		this.description = null;
		this.date = null;
		this.country = null;
		this.city = null;
		this.street = null;
		this.rating = 0;
		this.categoryId = null;
	}
	
	public Place (ParseObject pl){
		this.id = pl.getObjectId();
		this.name = pl.getString("name");
		this.description = pl.getString("description");
		this.date = pl.getCreatedAt();
		this.country = pl.getString("country");
		this.city = pl.getString("city");
		this.street = pl.getString("street");
		this.rating = (float) pl.getDouble("rating");
		this.commentsArray = new ArrayList<String>();
		this.location = pl.getParseGeoPoint("location");
		this.categoryId = pl.getString("categoryId");
 		this.userID = pl.getString("userID");
				
	}
	
	public String getCategory() {
		return categoryId;
	}
	
	public void setCategory(String categoryId) {
		this.categoryId = categoryId;
	}
	
	public String getCountry() {
		return country;
	}
	
	public void setCountry(String country) {
		this.country = country;
	}
	
	public String getCity() {
		return city;
	}
	
	public void setCity(String city) {
		this.city = city;
	}
	
	public String getStreet() {
		return street;
	}
	
	public void setStreet(String street) {
		this.street = street;
	}
	
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public String getDescription() {
		return description;
	}
	
	public void setDescription(String description) {
		this.description = description;
	}
	
	public Date getDate() {
		return date;
	}
	
	public void setDate(Date date) {
		this.date = date;
	}
	
	public float getRating() {
		return rating;
	}
	
	public void setRating(float rating) {
		this.rating = rating;
	}
	
	public String getId() {
		return id;
	}
	
	public void setId(String id) {
		this.id = id;
	}
	
	public ParseGeoPoint getLocation() {
		return location;
	}
	
	public void setLongitude(ParseGeoPoint location) {
		this.location = location;
	}
	
	public String getUserID() {
		return this.userID;
	}
	
	public ArrayList<String> getCommentsArray(){
		return this.commentsArray;
	}
	
	public void setImagesArray(ArrayList<ParseFile> images){
		this.imagesArray=images;
		this.numOfImages=images.size();
	}
	
	public void setThumbnailArray(ArrayList<ParseFile> images){
		this.thumbnailsArray=images;
	}
	
	public ArrayList<ParseFile> getImagesArray(){
		return this.imagesArray;
	}
	
	public ArrayList<ParseFile> getThumbnailsArray(){
		return this.thumbnailsArray;
	}
	
	public int getNumOfImages(){
		return this.numOfImages;
	}
}